//package com.fingard.dsp.bank.directbank.boc02.utils;
//
//import com.sun.org.apache.xml.internal.security.utils.Base64;
//import sun.misc.BASE64Decoder;
//import sun.misc.BASE64Encoder;
//
//import java.io.UnsupportedEncodingException;
//import java.security.KeyFactory;
//import java.security.PrivateKey;
//import java.security.PublicKey;
//import java.security.spec.PKCS8EncodedKeySpec;
//import java.security.spec.X509EncodedKeySpec;
//
///**
// * Created by marlon on 2019/1/16.
// * 签名算法: "SHA1withRSA" 做签名验签
// */
//public class RSAHelper {
//    private static final String SIGN_ALGORITHMS = "SHA1withRSA";
//    /**
//     * RSA签名
//     *
//     * @param content    待签名数据
//     * @param privateKey 商户私钥
//     * @param encode     字符集编码
//     * @return 签名值
//     */
//    public static String sign(String content, String privateKey, String encode) {
//        try {
//            PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(privateKey));
//
//            KeyFactory keyf = KeyFactory.getInstance("RSA");
//            PrivateKey priKey = keyf.generatePrivate(priPKCS8);
//
//            java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
//
//            signature.initSign(priKey);
//            signature.update(content.getBytes(encode));
//
//            byte[] signed = signature.sign();
//
//            return new BASE64Encoder().encode(signed);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        return null;
//    }
//
//    /**
//     * RSA验签名检查
//     *
//     * @param content   待签名数据
//     * @param sign      签名值
//     * @param publicKey 分配给开发商公钥
//     * @param encode    字符集编码
//     * @return 布尔值
//     */
//    public static boolean verifySignData(String content, String sign, String publicKey, String encode) {
//        try {
//            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//            byte[] encodedKey = Base64.decode(publicKey);
//            PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
//
//
//            java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
//
//            signature.initVerify(pubKey);
//            signature.update(content.getBytes(encode));
//
//            boolean bverify = signature.verify(Base64.decode(sign));
//            return bverify;
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        return false;
//    }
//
//    public static void main(String args[]){
//        //签名验签测试
//        String pubkey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAE7nmbTK0lVOXixIrWc78HJFcEnItcMRFGJJr\n" +
//                "jvawFGFlg2khl4731AmNl5JJxDA5l6kchYuPi1rhknf3JclCwyms/KJcwTkBRA+ucNK9pHMmhhuh\n" +
//                "an/cc9d1nqOyP6DFpo1XmSXx9aBr+A6xJuqtnsK2UjfyAFeC98U2EBLMCQIDAQAB\n";
//        String privatekey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIATueZtMrSVU5eLEitZzvwckVwS\n" +
//                "ci1wxEUYkmuO9rAUYWWDaSGXjvfUCY2XkknEMDmXqRyFi4+LWuGSd/clyULDKaz8olzBOQFED65w\n" +
//                "0r2kcyaGG6Fqf9xz13Weo7I/oMWmjVeZJfH1oGv4DrEm6q2ewrZSN/IAV4L3xTYQEswJAgMBAAEC\n" +
//                "gYBLo9rJpLoqfnpk6KRtZ9ffezu55cb64Tt5Fz76OO+mJBM1cbu4NBsicF7H+blSyYQ1r0UX7CL1\n" +
//                "PrcIu4kQNIe8hlediNCrhnscyhNqyXTuhSMl47hRcUpndNFGdSJ+5SvvjC7jHMU+w15gGh0iP6AB\n" +
//                "H2GvFZ3trYj1FyLfDEz4xQJBANWnsJcTDuDOjJm2vIKt4iM+f2tu/AA1hhG5oB5ITdYoSym3weWM\n" +
//                "9s33LB+TALaI5CdEbUmlLMqqZ9cOLybCAiMCQQCZdgdEeyzWiWbGRVyLVlnkyk3Owzt6rmQejhFA\n" +
//                "MZBzepp8a95/u9qW6PC8xLTzkKSmY4ctiiTBHiTbR7Cpdm3jAkANf/wDf7vH7qUprUc6BpysV22b\n" +
//                "rzaTGM6w3gbFAxKP/pnJOAgzZfXOS9jo4dQAtKOd64/wQFSVNbE8AHRwQX/7AkA4raP/gfLMhdDk\n" +
//                "l8eXWtw2qRVVsTutku09b8ElUWkFjZmzLG/wA2S3ae9H+OrQLnLxVT8e7a+nd8erCW5RGIF7AkA8\n" +
//                "e3w4jWnuXcKVUpSWOBhIlln0QzMnsKtbXYh14dN29DCsmHipFBunTvIOYoDOTIvQlgaLiWxE8pDV\n" +
//                "M2WflyLK\n";
//        String sing = "<request>\n" +
//                "      <acctNbr>449474690618</acctNbr>\n" +
//                "      <usage>JS</usage>\n" +
//                "      <rmtInf>\n" +
//                "        <prNm>1212</prNm>\n" +
//                "        <pymtAcct>449474690618</pymtAcct>\n" +
//                "        <peAcctNm>wa+UAZQmECKB732dcKIXLQ==</peAcctNm>\n" +
//                "        <peAcctNbr>ugI+a8j/uCQq6v6e8SAYAtw4AdZzfVtFaeJlKdg7MWgYHwYj8pz/FkkxwyjH0nfp</peAcctNbr>\n" +
//                "        <rcvBnkNm>eWxG5plXqIJZ9MWxTCI3xpHylx6jd4ElWitM1QDsuOcRf+u0gWiESI6CP+6y7QyUvrsdLE6lK7xqJTsud4d30qbmsCquQ/cunWpsmPBCRU8=</rcvBnkNm>\n" +
//                "        <rcvBnkNbr></rcvBnkNbr>\n" +
//                "        <txAmt>IgYWjHagEI0Lec5AyLQOew==</txAmt>\n" +
//                "        <remark>Ae7mWxVHrVrxzof8Vtc0ww==</remark>\n" +
//                "        <reqSeqNbr></reqSeqNbr>\n" +
//                "        <idTp></idTp>\n" +
//                "        <idNo></idNo>\n" +
//                "      </rmtInf>\n" +
//                "    </request>";
//        String signdata = sign(sing,privatekey,"utf-8");
//
//        /*String signdata = "NjXM+SiAAD68hP1WM+gtlOs87wmhWYBLRSGosQr7k9NOWvTloDp4GafLXwEt40LXeskQNrh5yR3E\n" +
//                "11gyM600PC+ZLMpERWhophi1q79TfbK0B8xD0aavNUSsbFjDXh25tVjw8MNS+nYRRKOARK8HrUbl\n" +
//                "yZvLzrxZhFtdiGj/35o=";*/
//
//        System.out.println("签名后的数据"+signdata);
//        boolean success = false;
//        try {
//            success = verifySignData(sing,new String(signdata.getBytes(),"utf-8"),pubkey,"utf-8");
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//        System.out.print("验签结果:"+success);
//    }
//}
